//
//  SortViewController.swift
//  ShareMusic
//
//  Created by 胡岩 on 16/5/3.
//  Copyright © 2016年 胡岩. All rights reserved.
//

import UIKit

class SortViewController: SMBViewController, UITableViewDelegate, UITableViewDataSource {
    var tableView:UITableView?
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.setNavigationBarHidden(true, animated: animated)
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        self.initView()
    }
    
    func initView() {
        self.tableView = UITableView.init(frame: self.view.bounds, style: UITableViewStyle.Plain)
        self.view.addSubview(self.tableView!)
        self.tableView?.delegate = self
        self.tableView?.dataSource = self
        self.tableView?.scrollEnabled = false
        self.tableView?.separatorStyle = UITableViewCellSeparatorStyle.None
        self.tableView?.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
        let swipe:UISwipeGestureRecognizer = UISwipeGestureRecognizer.init(target: self, action: #selector(self.swipeLeft(_:)))
        swipe.direction = UISwipeGestureRecognizerDirection.Left
        self.tableView?.addGestureRecognizer(swipe)
    }
    
    
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
        if indexPath.section == 0 {
            cell.textLabel?.text = "收藏列表"
        } else if indexPath.section == 1 {
            cell.textLabel?.text = "下载列表"
        } else if indexPath.section == 2 {
            cell.textLabel?.text = "定时关闭"
        } else if indexPath.section == 3 {
            cell.textLabel?.text = "搜索"
        }
        return cell
    }
    
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        if indexPath.section == 0 {
            let songList:SongsViewController = SongsViewController()
            songList.type = SongListsType.Collect
            songList.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(songList, animated: true)
        } else if indexPath.section == 1 {
            let songList:SongsViewController = SongsViewController()
            songList.type = SongListsType.Download
            songList.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(songList, animated: true)
        } else if indexPath.section == 2 {
            let time:TimeToOverView = TimeToOverView.init(frame: UIScreen.mainScreen().bounds)
            time.show()
        } else if indexPath.section == 3 {
            let songList:SongsViewController = SongsViewController()
            songList.type = SongListsType.Search
            songList.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(songList, animated: true)
        }
    }
    
    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 50
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 5
    }
    
    func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if section == 4 {
            return 1000
        }
        return 10.0
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
